package sanrenxing.dayEnd.backRepertoryTotal.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.ExchangeVarietyRateDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.ExchangeVarietyRate;
import sanrenxing.dayEnd.backRepertoryTotal.service.ExchangeVarietyRateBiz;

import java.util.HashMap;
import java.util.List;

@Service("exchangeVarietyRateBiz")
public class ExchangeVarietyRateBizImpl implements ExchangeVarietyRateBiz {
    @Autowired
    private ExchangeVarietyRateDao exchangeVarietyRateDao;
    /**
     * 将基金实体添加数据库基金表中
     *
     * @param exchangeVarietyRate 基金对象
     * @return 0:添加失败,1:添加成功
     */
    @Override
    public int add(ExchangeVarietyRate exchangeVarietyRate) {
        return exchangeVarietyRateDao.add(exchangeVarietyRate);
    }

    /**
     * 从表中根据基金编号字符串删除一行数据
     * @param BreedRateId 基金编号字符串
     * @return 删除影响的行数(0 : 删除失败, 1 : 删除成功)
     */
    @Override
    public int delete(String BreedRateId) {
        //判断是否为批量删除
        if(BreedRateId.contains(",")){
            //对编号按“，”分割
            String[] strs=BreedRateId.split(",");
            //循环删除
            for(String str:strs){
                //调用方法删除
                exchangeVarietyRateDao.delete(str);
            }
            //返回1
            return 1;
        }
        return exchangeVarietyRateDao.delete(BreedRateId);
    }

    /**
     * 修改数据到foundation表
     *
     * @param exchangeVarietyRate 员工对象
     * @return 0:修改失败,1:修改成功
     */
    @Override
    public int update(ExchangeVarietyRate exchangeVarietyRate) {
        return exchangeVarietyRateDao.update(exchangeVarietyRate);
    }

    /**
     * 按条件分页查询
     * @param exchangeVarietyRate
     * @param row
     * @param page
     * @return
     */
    @Override
    public List<ExchangeVarietyRate> queryAll(ExchangeVarietyRate exchangeVarietyRate, int row, int page) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("exchangeVarietyRate",exchangeVarietyRate);
        map.put("start",page);
        map.put("end",(page+row));
         return exchangeVarietyRateDao.queryAll(map);
    }

    /**
     * 按条件统计记录数
     *
     * @param exchangeVarietyRate 统计条件
     * @return 记录行数据
     */
    @Override
    public int count(ExchangeVarietyRate exchangeVarietyRate) {
        return exchangeVarietyRateDao.count();
    }
}
